//
//  PPPhotoView.m
//  pickpic
//
//  Created by 胡文广 on 2017/4/16.
//  Copyright © 2017年 MicroDream. All rights reserved.
//

#import "PPPhotoView.h"

#define kNormalInnerDescLineDistance 6



@interface PPPhotoView()

@end
@implementation PPPhotoView
- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = COLOR(0, 0, 0, 0.5);
        
    }
    return self;
}
- (PPCustomLabel *)labelDesc{

    if (!_labelDesc) {
        _labelDesc = [[PPCustomLabel alloc] initWithFrame:CGRectZero insets:UIEdgeInsetsMake(kNormalInnerDescTop, kLeftAndRightMargin, kNormalInnerDescBottom, kLeftAndRightMargin)];
        _labelDesc.font = kNormalInnerDescFont;
        _labelDesc.textColor = WHITE;
        _labelDesc.textAlignment = NSTextAlignmentLeft;
        _labelDesc.backgroundColor = CLEAR;
        _labelDesc.numberOfLines = 0;
        
    }
    return _labelDesc;
}
- (void)setDesc:(NSString *)desc{

    _desc = [desc copy];

    [self.labelDesc changeLineSpaceForLabelWithSpace:kNormalInnerDescLineDistance/2 text:_desc labelFont:kNormalInnerDescFont];
    
    [self addSubview:self.labelDesc];
}

- (void)layoutSubviews{

    [super layoutSubviews];
    self.labelDesc.frame = self.bounds;

}
//描述文字的行间距6pt，左右边距14pt，上边距8pt，下边距13pt，
-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    
    paraStyle.alignment = NSTextAlignmentLeft;
    
    paraStyle.lineSpacing = kNormalInnerDescLineDistance/2;
    
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle
                          };
    return  [str boundingRectWithSize:CGSizeMake(width,MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.height;;
    
}

@end
